﻿using System;
using System.Collections.Generic;
using System.Windows;

namespace MagicKey.Components.UserManager
{
    public class User
    {

        #region Fields

        /// <summary>
        /// The id of the current user.
        /// </summary>
        private int id;

        /// <summary>
        /// The name of the current user.
        /// </summary>
        private String name;

        /// <summary>
        /// The encrypted password of the current user.
        /// </summary>
        private String encryptedPassword;

        /// <summary>
        /// The private key of the current user.
        /// </summary>
        private String privateKey;

        /// <summary>
        /// The public key of the current user.
        /// </summary>
        private String publicKey;

        /// <summary>
        /// The role the current user belongs to.
        /// </summary>
        private String role;

        /// <summary>
        /// The salt the current user belongs to.
        /// </summary>
        private String salt;

        private List<String> myFiles;
        private List<String> otherUserFiles;

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="User" /> class.
        /// </summary>
        public User()
        {
            this.name = String.Empty;
            this.encryptedPassword = String.Empty;
        }

        public User(String name)
        {
            this.name = name;
            this.encryptedPassword = String.Empty;
        }
        public User(String name, String encryptedPassword)
        {
            this.name = name;
            this.encryptedPassword = encryptedPassword;
        }

        #endregion Constructors

        #region Properties

        /// <summary>
        /// Gets and sets property of the id field.
        /// </summary>
        public int Id
        {
            get
            {
                return this.id;
            }

            set
            {
                this.id = value;
            }
        }

        /// <summary>
        /// Gets and sets property of the name field.
        /// </summary>
        public String Name
        {
            get
            {
                return this.name;
            }

            set
            {
                this.name = value;
            }
        }

        /// <summary>
        /// Gets and sets property of the privateKey field.
        /// </summary>
        public String PrivateKey
        {
            get
            {
                return this.privateKey;
            }

            set
            {
                this.privateKey = value;
            }
        }

        /// <summary>
        /// Gets and sets property of the publicKey field.
        /// </summary>
        public String PublicKey
        {
            get
            {
                return this.publicKey;
            }

            set
            {
                this.publicKey = value;
            }
        }

        /// <summary>
        /// Gets and sets property of the encryptedPassword field.
        /// </summary>
        public String EncryptedPassword
        {
            get
            {
                return this.encryptedPassword;
            }

            set
            {
                this.encryptedPassword = value;
            }
        }

        /// <summary>
        /// Gets and sets property of the role field.
        /// </summary>
        public String Role
        {
            get
            {
                return this.role;
            }

            set
            {
                this.role = value;
            }
        }

        /// <summary>
        /// Gets and sets property of the salt field.
        /// </summary>
        public String Salt
        {
            get
            {
                return this.salt;
            }

            set
            {
                this.salt = value;
            }
        }

        public List<string> MyFiles
        {
            get
            {
                return this.myFiles;
            }

            set
            {
                this.myFiles = value;
            }
        }
        public List<string> OtherUserFiles
        {
            get
            {
                return this.otherUserFiles;
            }

            set
            {
                this.otherUserFiles = value;
            }
        }

        #endregion Properties

        #region Methods

        public bool AddMyFile(string path)
        {
            if (this.myFiles == null)
            {
                this.myFiles = new List<string>();
            }
            try
            {
                this.myFiles.Add(path);
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }

        }

        public bool RemoveMyFile(string path)
        {
            if (this.myFiles != null)
            {
                try
                {
                    this.myFiles.Remove(path);
                    return true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return false;
                }

            }
            return false;
        }
        public bool AddOtherUserFile(string path)
        {
            if (this.otherUserFiles == null)
            {
                this.otherUserFiles = new List<string>();
            }
            try
            {
                this.otherUserFiles.Add(path);
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }

        }

        public bool RemoveOtherUserFile(string path)
        {
            if (this.otherUserFiles != null)
            {
                try
                {
                    this.otherUserFiles.Remove(path);
                    return true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return false;
                }

            }
            return false;
        }

        #endregion Methods

    }
}
